home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-05-20 | 3.4 KB | 124 lines | [TEXT/MPS ] |
- {Written by Nicholas Pisarro, Jr., Aperture Technologies, Inc.
- No rights reserved.}
-
- UNIT VirusCheck;
-
- INTERFACE
-
- USES
- {$LOAD}
- MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf;
-
-
- {Returns TRUE if Application can run.}
- FUNCTION ApplicationCanRun: BOOLEAN;
-
-
- IMPLEMENTATION
-
- {Returns TRUE if Application can run.}
- FUNCTION ApplicationCanRun: BOOLEAN;
- CONST
- kVirusChkKinds = '????'; {Rsrc type for the # 'CODE' & # of Kinds of resources}
- kVirusChkID = 32; {Resource ID for the Virus Check Rsrc}
-
- {The Virus found alert and its sub-messages}
- kVirusAlrt = 1282; {A Virus has been detected!}
- kCountRsrcMissing = 1; {The Resource count Resource is missing}
- kTypeMiscount = 2; {Wrong number of resource types}
- kRsrcMiscount = 3; {Wrong number of a specific res. kind}
-
- TYPE
- {Resource & Count list.}
- RsrcCount = RECORD
- RType: ResType;
- RCount: INTEGER;
- END;
-
- RsrcRSRC = ARRAY[0..32000] OF RsrcCount;
- pRsrcRSRC = ^RsrcRSRC;
- hRsrcRSRC = ^pRsrcRSRC;
-
- VAR
- {For counting Resources.}
- theResType: ResType; { The kind we’re looking for }
- subMsgNo: INTEGER; { Submessage number }
- msgStr, { Submessage to go into dialog}
- workStr: Str255; { Resource name to go into the message }
-
- aRsrcRSRC: hRsrcRSRC; { Handle to the Count Rsrc}
-
- i: INTEGER;
- dummy: INTEGER;
-
- LABEL 100;
- BEGIN { ApplicationCanRun }
- ApplicationCanRun := FALSE; {Assume failure.}
-
- {Virus Check: Load resources with counts of various kinds of resources
- in Application. Make sure the counts in the resource match the actual
- counts in Application.}
- workStr[0] := CHR(0); {Make WorkStr have no length.}
-
- {Try to get the counts of the various resources in the Application.}
- aRsrcRSRC := hRsrcRSRC(Get1Resource(kVirusChkKinds, kVirusChkID));
- IF aRsrcRSRC <> NIL THEN BEGIN
-
- {Check out each of the counts read.}
- FOR i := 0 TO GetHandleSize(Handle(aRsrcRSRC)) div SIZEOF(RsrcCount) - 1 DO BEGIN
-
- {If the kind is a 0, a total resource count is wanted.}
- IF ORD(aRsrcRSRC^^[i].RType[1]) = 0 THEN BEGIN
-
- {Does the total number of resource kinds in the Application
- match the count the resource?}
- IF (Count1Types <> aRsrcRSRC^^[i].RCount) THEN BEGIN
-
- subMsgNo := kTypeMiscount; { Sub message }
-
- {Issue a Virus Alert to the user.}
- 100: GetIndString(msgStr, kVirusAlrt, subMsgNo);
- ParamText(msgStr, workStr, '', '');
- dummy := StopAlert(kVirusAlrt, NIL);
-
- EXIT(ApplicationCanRun);
- END;
- END
-
- {Otherwise, check a specific type.}
- ELSE BEGIN
-
- {Does the number of this kind of resource in the Application
- match the count the resource?}
- theResType := aRsrcRSRC^^[i].RType;
- IF Count1Resources(theResType) <> aRsrcRSRC^^[i].RCount THEN BEGIN
-
- { Make a string out of the resource type. }
- WorkStr[0] := CHR(4);
- BlockMove(@theResType[1], @workStr[1], 4);
-
- subMsgNo := kRsrcMiscount; { Sub message }
-
- GOTO 100;
- END;
- END;
- END; {End FOR i…}
-
- {Finished with the resource}
- ReleaseResource(Handle(aRsrcRSRC));
- END {End IF aRsrcRSRC <> NIL}
-
- {Count Resource not found.}
- ELSE BEGIN
- subMsgNo := kCountRsrcMissing; { Sub message }
-
- GOTO 100;
- END;
-
- {Possibly put other virus checks, checks for the proper system version,
- etc. here.}
-
- ApplicationCanRun := TRUE; {Success!}
- END; { ApplicationCanRun }
-
- END.